home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar / 1998 / May / di9805bt / fixtext / FIXTEXTF.PAS < prev   
Pascal/Delphi Source File  |  1997-12-29  |  3KB  |  116 lines

  1. unit Fixtextf;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     CreateBtn: TButton;
  12.     ReadBtn: TButton;
  13.     DeleteBtn: TButton;
  14.     Label1: TLabel;
  15.     ReadCount: TLabel;
  16.     procedure CreateBtnClick(Sender: TObject);
  17.     procedure ReadBtnClick(Sender: TObject);
  18.     procedure DeleteBtnClick(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.DFM}
  31.  
  32. type
  33.   TAddress = record
  34.     name:       array[1..35] of Char;
  35.     addr:       array[1..35] of Char;
  36.     city:       array[1..18] of Char;
  37.     state:      array[1..2] of Char;
  38.     zip:        array[1..10] of Char;
  39.     delimiter:  array[1..2] of Char;
  40.   end;
  41.  
  42. procedure PasToArray(const str: String;
  43.                      var arr: array of Char);
  44. {
  45. Copies a Pascal String to a Char array.  The
  46. array is padded with blanks.
  47. }
  48. var
  49.   i, j:     Word;
  50. begin
  51.   {Copy the string to the array.}
  52.   for i := 1 to Length(str) do arr[i - 1] := str[i];
  53.   {Fill the array with spaces in case the
  54.    string is shorter than the array.}
  55.   j := i + 1;
  56.   for i := j to High(arr) do arr[i] := ' ';
  57. end;
  58.  
  59. procedure TForm1.CreateBtnClick(Sender: TObject);
  60. const
  61.   MaxRecs = 100;
  62. var
  63.   buff:         array[1..MaxRecs] of TAddress;
  64.   addrFile:     File;
  65.   i, count:     Integer;
  66. begin
  67.   AssignFile(addrFile, 'addr.dat');
  68.   Rewrite(addrFile, SizeOf(TAddress));
  69.   {initialize the buffer}
  70.   FillChar(buff,SizeOf(Buff),#0);          {added by RLV on 12/29/97}
  71.   {Put 100 records into the buffer.}
  72.   for i := 1 to MaxRecs do
  73.     with buff[i] do
  74.     begin
  75.       PasToArray('John Doe', name);
  76.       PasToArray('123 East Main Street', addr);
  77.       PasToArray('New York', city);
  78.       PasToArray('NY', state);
  79.       PasToArray('55555-5555', zip);
  80.       delimiter[1] := #13;
  81.       delimiter[2] := #10;
  82.     end;
  83.     {Write 100 buffers (10,000 records.}
  84.     for i := 1 to 100 do
  85.       BlockWrite(addrFile, buff, MaxRecs, count);
  86.     System.Close(addrFile);
  87. end;
  88.  
  89. procedure TForm1.ReadBtnClick(Sender: TObject);
  90. const
  91.   MaxRecs = 100;
  92. var
  93.   buff:         array[1..MaxRecs] of TAddress;
  94.   addrFile:     File;
  95.   total,
  96.   count:        Integer;
  97. begin
  98.   AssignFile(addrFile, 'addr.dat');
  99.   Reset(addrFile, SizeOf(TAddress));
  100.   {Read the file 100 records at a time.}
  101.   total := 0;
  102.   repeat
  103.     BlockRead(addrFile, buff, MaxRecs, count);
  104.     total := total + count;
  105.     ReadCount.Caption := IntToStr(total);
  106.   until count = 0;
  107.   System.Close(addrFile);
  108. end;
  109.  
  110. procedure TForm1.DeleteBtnClick(Sender: TObject);
  111. begin
  112.   DeleteFile('addr.dat');
  113. end;
  114.  
  115. end.
  116.